import { defineConfig } from "vite";
import vue from "@vitejs/plugin-vue";
import path, { resolve } from "node:path";
import electron from "vite-plugin-electron/simple";
import Pages from "vite-plugin-pages";
import Components from "unplugin-vue-components/vite";
import { AntDesignVueResolver } from "unplugin-vue-components/resolvers";
// https://vite.dev/config/
export default defineConfig({
  build: {
    rollupOptions: {
      input: {
        main: resolve(__dirname, "index.html"), // 修改为根目录的index.html
        speedBall: resolve(__dirname, "public/speed-ball.html"), // 小球
      },
    },
    outDir: "dist", // 确保输出目录正确
    emptyOutDir: true, // 构建前清空输出目录
    sourcemap: true, // 生成sourcemap以便调试
  },
  plugins: [
    vue(),
    Pages({
      // 可选配置：默认情况下插件会使用 `src/pages` 目录
      dirs: "src/pages", // 页面文件目录
      extensions: ["vue"], // 支持的文件扩展名
      exclude: ["**/components/*.vue"],
    }),
    electron({
      main: {
        // Shortcut of `build.lib.entry`
        entry: "electron/main.ts",
      },
      preload: {
        // Shortcut of `build.rollupOptions.input`
        input: "electron/preload.ts",
      },
      // Optional: Use Node.js API in the Renderer process
      renderer: {},
    }),
    Components({
      dts: false,
      resolvers: [
        AntDesignVueResolver({
          importStyle: false, // css in js
        }),
      ],
    }),
  ],
  resolve: {
    alias: {
      "@": path.join(__dirname, "src"),
    },
  },
});
